package net.gyapp.markim.testing;

import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.easyder.wrapper.base.view.WrapperSwipeActivity;
import com.easyder.wrapper.core.model.BaseVo;

import net.gyapp.markim.ApiConfig;
import net.gyapp.markim.R;
import net.gyapp.markim.core.ImManager;
import net.gyapp.markim.module.basic.base.BaseRecyclerHolder;
import net.gyapp.markim.module.basic.base.CommonPresenter;
import net.gyapp.markim.utils.RequestParams;

import java.util.Arrays;

import butterknife.BindView;
import me.winds.widget.autolayout.utils.AutoUtils;
import me.winds.widget.usage.TitleView;

/**
 * Auther:  winds
 * Email:   heardown@163.com
 * Date:    2018/8/4.
 * Desc:
 */
public class TestListActivity extends WrapperSwipeActivity<CommonPresenter> {

    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;

    public static Intent getIntent(Context context) {
        return new Intent(context, TestListActivity.class);
    }

    @Override
    protected int getViewLayout() {
        return R.layout.common_recycler;
    }

    @Override
    protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                super.getItemOffsets(outRect, view, parent, state);
                outRect.set(0, 0, 0, AutoUtils.getPercentHeightSize(30));
            }
        });

        String[] list = {"获取群信息", "获取群成员", "获取群小程序", "获取群禁言状态", "获取群申请信息",
            "获取指定用户", "获取所有用户"
            };
        final String groupNumber = "100";
        mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                switch (position) {
                    case 0:
                        getGroupInfo(groupNumber);
                        break;
                    case 1:
                        getGroupUser(groupNumber);
                        break;
                    case 2:
                        getGroupProject(groupNumber);
                        break;
                    case 3:
                        getGroupShieldStatus(groupNumber);
                        break;
                    case 4:
                        getGroupVerifyInfo();
                        break;
                    case 5:
                        ImManager.getInstance().getUser("test05");
                        break;
                    case 6:
                        ImManager.getInstance().getAllUser();
                        break;
                }
            }
        });

        mRecyclerView.setAdapter(new BaseQuickAdapter<String, BaseRecyclerHolder>(R.layout.item_text, Arrays.asList(list)) {

            @Override
            protected void convert(BaseRecyclerHolder helper, String item) {
                helper.setText(R.id.tv_text, item);
            }
        });

    }

    @Override
    protected void loadData(Bundle savedInstanceState, Intent intent) {

    }

    @Override
    public void showContentView(String url, BaseVo dataVo) {

    }


    /**
     * 获取群成员信息
     *
     * @param groupNumber
     */
    private void getGroupUser(String groupNumber) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_GET_GROUP_USERS, new RequestParams().put("groupNumber", groupNumber).get());
    }

    /**
     * 获取群信息
     *
     * @param groupNumber
     */
    private void getGroupInfo(String groupNumber) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_GET_GROUP_INFO, new RequestParams().put("groupNumber", groupNumber).get());
    }

    /**
     * 获取群申请信息
     */
    private void getGroupVerifyInfo() {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_GET_GROUP_VERIFY_INFO, BaseVo.class);
    }

    /**
     * 获取群屏蔽状态
     *
     * @param groupId
     */
    private void getGroupShieldStatus(String groupId) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_GET_SHIELD_GROUP_STATUS, new RequestParams().put("groupId", groupId).get(), BaseVo.class);
    }

    /**
     * 设置群屏蔽
     *
     * @param groupId
     */
    private void setGroupShieldStatus(String groupId) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_GET_SHIELD_GROUP_STATUS, new RequestParams().put("groupId", groupId).get(), BaseVo.class);
    }


    /**
     * 获取群小程序
     *
     * @param groupNumber
     */
    private void getGroupProject(String groupNumber) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_GET_SMALL_PROGRAM, new RequestParams().put("groupNumber", groupNumber).get());
    }

    /**
     * 设置群小程序
     *
     * @param groupNumber
     * @param groupTitle
     * @param groupTitleUrl
     */
    private void setGroupProject(String groupNumber, String groupTitle, String groupTitleUrl) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_GET_SMALL_PROGRAM, new RequestParams().put("groupNumber", groupNumber).put("groupTitle", groupTitle).put("groupTitleUrl", groupTitleUrl).get());
    }

    /**
     * 更新群通知
     *
     * @param groupNumber
     * @param groupNotice
     */
    private void updateGroupNotice(String groupNumber, String groupNotice) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_GET_SMALL_PROGRAM, new RequestParams().put("groupNumber", groupNumber).put("groupNotice", groupNotice).get());
    }

    /**
     * 同意入群
     *
     * @param groupUsersId
     */
    private void setAgreeEntryGroup(String groupUsersId) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_AGREE_USER_ENTRY_GROUP, new RequestParams().put("groupUsersId", groupUsersId).get());
    }

    /**
     * 拒绝入群
     *
     * @param groupUsersId
     */
    private void setRefuseEntryGroup(String groupUsersId) {
        presenter.setNeedDialog(false);
        presenter.postData(ApiConfig.API_AGREE_USER_ENTRY_GROUP, new RequestParams().put("groupUsersId", groupUsersId).get());
    }
}
